<?php
/**
 * site model
 */
class Model_Commentor_Site extends Model_Base
{
    /**
     * table name
     * must be set within each object
     *
     * @access protected
     */
    protected $tableName = 'sites';


    /**
     * unique id
     * must be set within each object
     *
     * @access protected
     */
    protected $keys = 'id';

    /**
     * the internal data KEY array
     * used for internal objects/values attached to this object
     * MUST BE SET BEFORE HAND
     *
     * @format array['name' => 'type']
     * @access protected
     * @var    array
     */
    protected $internalVars = array(
       'url' => 'str',
       'name' => 'str',
       'key' => 'str',
       'active' => 'str',
    );


    /**
     * the external data KEY array
     * used for external objects/values attached to this object
     * so it doesn't ruin the rawData which will be used to save into db
     * IT STORES ONLY THE KEYS - SO WHEN USING GETRAWDATA, THESE ARE EXEMPTED
     * MUST BE SET BEFORE HAND
     *
     * @format array['name' => 'type']
     * @access protected
     * @var    array
     */
    protected $externalVars = array(
    );


/*--------------------------------------[getters]--------------------------------------*/

    /**
     * get url: site url
     *
     * @return str
     */
    public function getUrl()
    {
        return $this->_getVar('url');

    }// end getUrl


    /**
     * get name: site name
     *
     * @return str
     */
    public function getName()
    {
        return $this->_getVar('name');

    }// end getName


    /**
     * get key: auth key (generated)
     *
     * @return str
     */
    public function getKey()
    {
        return $this->_getVar('key');

    }// end getKey


    /**
     * get active: Y|N
     *
     * @return str
     */
    public function getActive()
    {
        return $this->_getVar('active') == 'Y';

    }// end getActive


/*--------------------------------------[setters]--------------------------------------*/

    /**
     * set url
     *
     * @param str $Url site url
     *
     * @return Default_Model_Sites
     */
    public function setUrl($Url)
    {
        return $this->_setVar('url', $Url);

    }// end setUrl


    /**
     * set name
     *
     * @param str $Name site name
     *
     * @return Default_Model_Sites
     */
    public function setName($Name)
    {
        return $this->_setVar('name', $Name);

    }// end setName


    /**
     * set key
     *
     * @param str $Key auth key (generated)
     *
     * @return Default_Model_Sites
     */
    public function setKey($Key)
    {
        return $this->_setVar('key', $Key);

    }// end setKey


    /**
     * set active
     *
     * @param str $Active Y|N
     *
     * @return Default_Model_Sites
     */
    public function setActive($Active)
    {
        $Active = $Active? 'Y' : 'N';
        return $this->_setVar('active', $Active);

    }// end setActive

/*--------------------------------------[special function]--------------------------------------*/

    /**
     * generate the auth key for this particular website.
     * @return $this
     */
    public function keyGen()
    {
        // formula: md5 sitename with current time at point of save...
        $key = md5($this->getName() . '-' . mktime());
        return $this->setKey($key);

    }// end keyGen

}// end Model_Commentor_Site
?>